//
//  StarLevelView.m
//  LimitFree
//
//  Created by lijinghua on 16/3/1.
//  Copyright © 2016年 lijinghua. All rights reserved.
//

#import "StarLevelView.h"

@interface StarLevelView  ()
{
    UIImageView *_backgroundImageView;//背景图片
    UIImageView *_foregroundImageView;//前景图片
}
@end

@implementation StarLevelView

//当从xib创建出来的view，调用的初始化方法是initWithCoder
- (id)initWithCoder:(NSCoder *)aDecoder{
    if(self = [super initWithCoder:aDecoder]){
        self.backgroundColor = [UIColor clearColor];
        _backgroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 65, 23)];
        _backgroundImageView.image = [UIImage imageNamed:@"StarsBackground.png"];
        _foregroundImageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 65, 23)];
        _foregroundImageView.image = [UIImage imageNamed:@"StarsForeground.png"];
        
        //设置填充模式为靠左
        _foregroundImageView.contentMode = UIViewContentModeLeft;
        _backgroundImageView.contentMode = UIViewContentModeLeft;
        //超出边界剪切掉
        _foregroundImageView.clipsToBounds = YES;
    
        [self addSubview:_backgroundImageView];
        [self addSubview:_foregroundImageView];
    }
    return self;
}

//根据星级设置，前景图片的frame
- (void)setStarLevel:(NSString*)startCurrent{
    float starLevel = [startCurrent floatValue];
    _foregroundImageView.frame = CGRectMake(0, 0, 65*starLevel/5.0, 23);
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
